package com.sikaryofficial.backend.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.sikaryofficial.backend.domain.dto.resp.music.MusicGenreVO;
import com.sikaryofficial.backend.domain.entity.MusicGenre;
import com.sikaryofficial.backend.mapper.MusicGenreMapper;
import com.sikaryofficial.backend.service.IMusicGenreService;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 音乐分类Service业务层处理
 *
 * @author qinjinyuan
 * @date 2024-08-07
 */
@Service
public class MusicGenreServiceImpl extends ServiceImpl<MusicGenreMapper, MusicGenre> implements IMusicGenreService {
    @Autowired
    private MusicGenreMapper musicGenreMapper;

    /**
     * 根据音乐id获取音乐分类
     *
     * @param musicId
     * @return
     */
    @Override
    public List<MusicGenreVO> getGenreListByMusicId(Long musicId) {
        List<Long> musicIds = Lists.newArrayList();
        musicIds.add(musicId);
        return musicGenreMapper.getGenreListByMusicIds(musicIds);
    }

    /**
     * 根据音乐id列表获取音乐分类
     *
     * @param musicIds
     * @return
     */
    @Override
    public Map<Long, List<MusicGenreVO>> getGenreListByMusicIds(List<Long> musicIds) {
        List<MusicGenreVO> musicGenreVOList = musicGenreMapper.getGenreListByMusicIds(musicIds);
        if (CollUtil.isEmpty(musicGenreVOList)) {
            return Maps.newHashMap();
        }
        return musicGenreVOList.stream().collect(Collectors.groupingBy(MusicGenreVO::getMusicId));
    }
}
